home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 9 / Night Owl CD-ROM (NOPV9) (Night Owl Publisher) (1993).ISO / 010a / cliptree.zip / ERRSAVE.PRG < prev    next >
Text File  |  1993-02-07  |  10KB  |  226 lines

  1. /*┌──────────────────────────────────────────────────────────────────────┐
  2.  ▌│                                                                      │
  3.  ▌│ Program Name: ERRSAVE.PRG       Copyright: (c) 1991 M&T Books        │
  4.  ▌│ Date Created: 1991               Language: Clipper 5.0               │
  5.  ▌│ Time Created:                      Author: Craig Yellick             │
  6.  ▌│                                                                      │
  7.  ▌│ 02/05/93 KSG                                                         │
  8.  ▌│ * removed default() in favor of curdrive()                           │
  9.  ▌│ * removed save/restore environment stuff                             │
  10.  ▌│ * added section to test for clock linked in, and if so uninstall it. │
  11.  ▌│ * removed most comments from this program file (i do not need um)!   │
  12.  ▌│ * tided up a little                                                  │
  13.  ▌└──────────────────────────────────────────────────────────────────────┘
  14.  ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀           */
  15.  
  16.  
  17. //  Convert integers to left-trimmed strings.
  18. #define lstr(n)  (ltrim(str(n)))
  19.  
  20. //  Convert logicals to text.
  21. #define YN(L)    if(L, "Yes", "No ")
  22.  
  23. //  Short-hand.
  24. #translate ifempty(<a>, <b>) => if(empty(<a>), <b>, <a>)
  25.  
  26. function ErrorSaver(e, defError, appTitle, filename)
  27.  
  28. local errEnv
  29. local varList_, trace_
  30. local i, r, c, sel, argStr, argCnt, osDescr
  31.  
  32.   i := 1
  33.   trace_ := {}
  34.   do while .not. empty(procname(i))
  35.     aadd(trace_, procname(i) +" (" +lstr(procline(i)) +")")
  36.         i++
  37.   enddo
  38.  
  39.   //  Build list of arguments (if any)
  40.   if valtype(e:args) = "A"
  41.     argStr := ""
  42.     aeval(e:args, { |s| argStr += (XtoS(s) +", ")} )
  43.     argStr := left(argStr, min(len(argStr) -2, 35))
  44.     argCnt := lstr(len(e:args))
  45.   else
  46.     argStr := "<none>"
  47.     argCnt := "0"
  48.   endif
  49.  
  50.   //  Build description of operating systen error
  51.   if e:osCode > 0
  52.     osDescr := lstr(e:osCode) +": " +left(DosErrText(e:osCode), 35)
  53.   else
  54.     osDescr := "0: n/a"
  55.   endif
  56.  
  57.   varList_ := {"arg count         " +argCnt,              ;
  58.                "args              " +argStr,              ;
  59.                "canDefault        " +YN(e:canDefault),    ;
  60.                "canRetry          " +YN(e:canRetry),      ;
  61.                "canSubstitute     " +YN(e:canSubstitute), ;
  62.                "description       " +e:description,       ;
  63.                "filename          " +e:filename,          ;
  64.                "genCode           " +lstr(e:genCode),     ;
  65.                "operation         " +e:operation,         ;
  66.                "osCode            " +osDescr,             ;
  67.                "severity          " +lstr(e:severity),    ;
  68.                "subCode           " +lstr(e:subCode),     ;
  69.                "subSystem         " +e:subSystem,         ;
  70.                "tries             " +lstr(e:tries),       ;
  71.                "----------------- ",                      ;
  72.                "Free memory   (0) " +lstr(memory(0)),     ;
  73.                "Largest block (1) " +lstr(memory(1)),     ;
  74.                "Run area      (2) " +lstr(memory(2))  }
  75.  
  76.  
  77.   //  Display screen heading
  78.   if valtype(appTitle) <> "C"
  79.     appTitle := ""
  80.   endif
  81.  
  82.   //  If filename was specified, open it up and append error info.
  83.   if valtype(filename) = "C"
  84.     set alternate to (filename) additive
  85.     set alternate on
  86.     set console off
  87.     ? replicate("=", 70)
  88.     ?  "ErrorSaver: This run-time error logged on "
  89.     ?? dtoc(date()) +" at " +time()
  90.     if .not. empty(appTitle)
  91.       ?  "Application: " +appTitle
  92.     endif
  93.     ?  "Operating system = " +os() +", network = "
  94.     ?? ifempty(netname(), "<none>")
  95.     ?  "Available diskspace = "
  96.     ??  ltrim(transform(diskspace(), "999,999,999,999")) +" in "
  97.     ?? curdrive()    + curdir()
  98.     ?  "PATH    = "  +ifempty(gete("PATH"),    "<none>")
  99.     ?  "COMSPEC = "  +ifempty(gete("COMSPEC"), "<none>")
  100.     ? replicate("-", 70)
  101.     ? "Traceback: Proc (Line)   Error Information"
  102.     ? "~~~~~~~~~~~~~~~~~~~~~~   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
  103.     for i := 1 to max(len(trace_), len(varList_))
  104.       if i <= len(trace_)
  105.         ? "  " +padr(trace_[i], 20)
  106.       else
  107.         ? space(22)
  108.       endif
  109.       ?? space(3)
  110.       if i <= len(varList_)
  111.          ?? varList_[i]
  112.       endif
  113.     next i
  114.     set console on
  115.     set alternate off
  116.     set alternate to
  117.   endif
  118.   setcolor('w/n')
  119.   scroll()
  120.   CMDHELP("BOMBOUT")
  121. return .f.
  122.  
  123. static function XtoS(x)
  124.     local s
  125.     if     valtype(x) = "C"
  126.         s := x
  127.     elseif valtype(x) = "N"
  128.         s := lstr(x)
  129.     elseif valtype(x) = "D"
  130.         s := dtoc(x)
  131.     elseif valtype(x) = "L"
  132.         s := if(x, ".t.", ".f.")
  133.     endif
  134. return s                                         // return a string
  135.  
  136. static function DosErrText(n)
  137. /*
  138.    Return description of DOS error code.
  139.    (Descriptions based on table D-1 in
  140.    Clipper 5.0 Programming & Utilities Guide.)
  141. */
  142. local descr_ := {;
  143.     "Invalid function number",                         ;  // 1
  144.     "File not found",                                  ;  // 2
  145.     "Path not found",                                  ;  // 3
  146.     "Too many files open (no handles left)",           ;  // 4
  147.     "Access denied",                                   ;  // 5
  148.     "Invalid handle",                                  ;  // 6
  149.     "Memory control blocks destroyed",                 ; // 7
  150.     "Insufficient memory",                             ;  // 8
  151.     "Invalid memory block address",                    ;  // 9
  152.     "Invalid environment",                             ;  // 10
  153.     "Invalid format",                                  ;  // 11
  154.     "Invalid access code",                             ;  // 12
  155.     "Invalid data",                                    ;  // 13
  156.     ,                                                  ;  // 14
  157.     "Invalid drive was specified",                     ;  // 15
  158.     "Attempt to remove the current directory",         ;  // 16
  159.     "Not same device",                                 ;  // 17
  160.     "No more files",                                   ;  // 18
  161.     "Attempt to write on write-protected diskette",    ;  // 19
  162.     "Unknown unit",                                    ;  // 20
  163.     "Drive not ready",                                 ;  // 21
  164.     "Unknown command",                                 ;  // 22
  165.     "Data error (CRC)",                                ;  // 23
  166.     "Bad request structure length",                    ;  // 24
  167.     "Seek error",                                      ;  // 25
  168.     "Unknown media type",                              ;  // 26
  169.     "Sector not found",                                ;  // 27
  170.     "Printer out of paper",                            ;  // 28
  171.     "Write fault",                                     ;  // 29
  172.     "Read fault",                                      ;  // 30
  173.     "General failure",                                 ;  // 31
  174.     "Sharing violation",                               ;  // 32
  175.     "Lock violation",                                  ;  // 33
  176.     "Invalid disk change",                             ;  // 34
  177.     "FCB unavailable",                                 ;  // 35
  178.     "Sharing buffer overflow",                         ;  // 36
  179.     ,,,,,,,,,,,,,                                      ;  // 37-49
  180.     "Network request not supported",                   ;  // 50
  181.     "Remote computer not listening",                   ;  // 51
  182.     "Duplicate name on network",                       ;  // 52
  183.     "Network name not found",                          ;  // 53
  184.     "Network busy",                                    ;  // 54
  185.     "Network device no longer exists",                 ;  // 55
  186.     "Network BIOS command limit exceeded",             ;  // 56
  187.     "Network adapter hardware error",                  ;  // 57
  188.     "Incorrect response from network",                 ;  // 58
  189.     "Unexpected network error",                        ;  // 59
  190.     "Incompatible remote adapter",                     ;  // 60
  191.     "Print queue full",                                ;  // 61
  192.     "Not enough space for print file",                 ;  // 62
  193.     "Print file deleted (not enough space)",           ;  // 63
  194.     "Network name deleted",                            ;  // 64
  195.     "Access denied",                                   ;  // 65
  196.     "Network device type incorrect",                   ;  // 66
  197.     "Network name not found",                          ;  // 67
  198.     "Network name limit exceeded",                     ;  // 68
  199.     "Network BIOS session limit exceeded",             ;  // 69
  200.     "Temporarily paused",                              ;  // 70
  201.     "Network request not accepted",                    ;  // 71
  202.     "Print or disk redirection paused",                ;  // 72
  203.     ,,,,,,,                                            ;  // 73-79
  204.     "File already exists",                             ;  // 80
  205.     ,                                                  ;  // 81
  206.     "Cannot make directory entry",                     ;  // 82
  207.     "Fail on INT 24h",                                 ;  // 83
  208.     "Too many redirections",                           ;  // 84
  209.     "Duplicate redirection",                           ;  // 85
  210.     "Invalid password",                                ;  // 86
  211.     "Invalid parameter",                               ;  // 87
  212.     "Network device fault",                            ;  // 88
  213.                                                        ;
  214.     "Undefined or reserved error code!" }                 // +1
  215.  
  216.   /*
  217.   *  Check that code number is within known upper limit,
  218.   *  and that a description is available for it.
  219.   */
  220.   if (n > (len(descr_) -1)) .or. (descr_[n] = nil)
  221.     n := len(descr_)
  222.   endif
  223.  
  224. return descr_[n]
  225.  
  226.